﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using WpfWordsLearner.Helper;
using System.Xml.Linq;

namespace WpfWordsLearner.ViewModels
{
	public sealed class NewDictionaryVM : BaseViewModel
	{
		private string _dicName;

		public string DictionaryName
		{
			get { return _dicName; }
			set { _dicName = value; OnPropertyChanged(() => DictionaryName); }
		}

		public ICommand CreateCommand{ get { return new BaseCommand(Create); } }
		private void Create()
		{
			XDocument doc=new XDocument();
			doc.Declaration=new XDeclaration("1.0","utf-8","yes");
			doc.Add(new XElement("Words"));
			doc.Save(System.IO.Path.Combine(App.pathToContent, DictionaryName));
			var wind = App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault(x => x.IsActive);
			if(wind!=null)
			{
				wind.DialogResult = true;
			}
		}
	}
}
